<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

function themeConfig($form)
{
    $logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL, NULL, _t('站点 LOGO 地址'), _t('在这里填入一个图片 URL 地址, 以在网站标题前加上一个 LOGO'));
    $form->addInput($logoUrl);

    $sidebarBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('sidebarBlock',
        array('ShowRecentPosts' => _t('显示最新文章'),
            'ShowRecentComments' => _t('显示最近回复'),
            'ShowCategory' => _t('显示分类'),
            'ShowArchive' => _t('显示归档'),
            'ShowOther' => _t('显示其它杂项')),
        array('ShowRecentPosts', 'ShowRecentComments', 'ShowCategory', 'ShowArchive', 'ShowOther'), _t('侧边栏显示'));

    $form->addInput($sidebarBlock->multiMode());
}


/**
 * 显示下一篇
 * @param $context
 * @param $text
 * @return void
 */
function theNext($context, $text, $not = '没有了')
{
    try {
        $db = Typecho_Db::get();
    } catch (Typecho_Db_Exception $e) {
    }
    $sql = $db->select()->from('table.contents')
        ->where('table.contents.created > ?', $context->created)
        ->where('table.contents.status = ?', 'publish')
        ->where('table.contents.type = ?', $context->type)
        ->where('table.contents.password IS NULL')
        ->order('table.contents.created', Typecho_Db::SORT_ASC)
        ->limit(1);

    $content = $db->fetchRow($sql);

    if ($content) {
        $content = $context->filter($content);
        $link = '<a href="' . $content['permalink'] . '">' . $text . '</a>';
    } else {
        $link = '<a href="javascript:void(0);">' . $not . '</a>';
    }
    echo $link;
}

/**
 * 显示上一篇
 *
 * @access public
 * @param $context
 * @param $text
 * @param string $not
 * @return void
 */
function thePrev($context, $text, $not = '没有了')
{
    try {
        $db = Typecho_Db::get();
    } catch (Typecho_Db_Exception $e) {
    }
    $sql = $db->select()->from('table.contents')
        ->where('table.contents.created < ?', $context->created)
        ->where('table.contents.status = ?', 'publish')
        ->where('table.contents.type = ?', $context->type)
        ->where('table.contents.password IS NULL')
        ->order('table.contents.created', Typecho_Db::SORT_DESC)
        ->limit(1);
    $content = $db->fetchRow($sql);
    if ($content) {
        $content = $context->filter($content);
        $link = '<a href="' . $content['permalink'] . '">' . $text . '</a>';
    } else {
        $link = '<a href="javascript:void(0);">' . $not . '</a>';
    }
    echo $link;
}

/*
function themeFields($layout) {
    $logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL, NULL, _t('站点LOGO地址'), _t('在这里填入一个图片URL地址, 以在网站标题前加上一个LOGO'));
    $layout->addItem($logoUrl);
}
*/

